<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>运算符</title>
</head>
<body>
    <script>
        //1. 算术运算符
        // + - * /  %
        //和C使用不一样的地方
        let b = false;//boolean
        //布尔类型允许参加计算的,true = 1,  false = 0
        console.log(b + 1);

        console.log("hello" + 3);//遇到了字符串,表示拼接

        console.log(3+3+""+3+5);//635

        console.log(9/2);//java取整,js除法

        console.log(10%3);// 取模

        //+= -= ++ --
        let s = 10;
        s+=2;//s = s + 2;
        console.log(s);//12

        //表达式 - 由变量/字面量以及运算符组成的合法的语句
        //前++和后++ - 变量本身都会自增1
        let i = 1;
        //++i;//i = i + 1;
        //i++;//i = i + 1;

        //let result = ++i; // 将i自增之后的值赋值给了变量result = 2
        let result2 = i++;// 将i自增前的值先赋值给了result2,然后自己自增1
        console.log(i);//2
        console.log(result2);//1

        let m = 1;
        //1 + 2
        let n = m++ + m--;//n = 3   m=1
        //2+2+2+2=8
        let result = ++m + --n + n-- + m--;
        console.log(result);

        //2.比较运算符 > < >= <= != == ===
        console.log(20 == "20");//true,数字形式的字符串"20"->number类型20,不关注类型,仅仅关注值本身
        //1. 类型
        //2. 比较值
        console.log(20 === "20");//全等于,恒等于  false

        //3. 位运算符
        //移位操作的
        //<< >>
        //2 << 2
        console.log(2 << 2);//8  0010  1000->8

        //计算-10的二进制
        //涉及到负数的二进制 - 以补码的方式存在
        //补码 = 反码 + 1
        //反码 = 对原码进行取反[符号位不变,其余位按位取反]

        //-10 的原码
        //10000000 00000000 00000000 00001010
        //11111111 11111111 11111111 11110101
        //                                  1
        //------------------------------------
        //11111111 11111111 11111111 11110110  

        //00000000 00000000 00000000 00001001 = ~9 = -10

        //11111111 11111111 11111111 11110110  

        //>> 带符号移动
        //1111111111 11111111 11111111 111101  = ~2 = -3
        //0000000000 00000000 00000000 000010 = 2
        console.log(-10 >> 2);

        //取反 - 9
        // ~9 = -10
        //结论 ~x = -(x+1)

        //00000000 00000000 00000000 00001001
        //11111111 11111111 11111111 11110110
        console.log(~9);

        // & | 非短路&和| 

        //逻辑运算符  && ||

    </script>
</body>
</html>